package ${packagePath}${controllerPackage};

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import frame.icloud.base.controller.BaseController;
import frame.icloud.common.util.text.Convert;
import frame.icloud.global.entity.queryResult.QueryResultModel;
import frame.icloud.global.entity.queryResult.QueryResultModelByPage;
import frame.icloud.global.entity.queryclause.QueryClauseByPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import ${packagePath}${entityPackage}.${entity};
import ${packagePath}${servicePackage}.${entity}Service;

/**
 * ${introduce}
 * author: ${author}
 * date: ${date}
 */
@Api(tags = "${entity} 创建人:${author} 创建时间:${date}")
@RestController
@RequestMapping("${entity?uncap_first}")
public class ${entity}Controller extends BaseController {

    /**
     * 当前表业务类
     */
    @Autowired
    private ${entity}Service ${entity?uncap_first}Service;
    
     /**
     * 自定义分页查询(页码)
     *
     * @param queryClause 查询参数
     * @return Page<${entity}>
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataTypeClass = QueryClauseByPage.class, name = "queryClause", value = "查询参数")
    })
    @ApiOperation(value = "自定义分页查询(页码)", notes = "自定义分页查询(页码)", httpMethod = "POST")
    @PostMapping("listPageByWhere")
    public QueryResultModelByPage<?> getListPageByWhere(@RequestBody QueryClauseByPage queryClause) {
        QueryResultModelByPage<Object> returnValue = new QueryResultModelByPage<Object>();
        
        //获取数据
        Page<${entity}> page = ${entity?uncap_first}Service.getListPageByWhere(queryClause);
        
        returnValue.setData(page.getRecords());
        
        //获取总页数
        returnValue.setTotal(Convert.toInt(page.getTotal()));
        
        //返回
        return returnValue;
    }

    /**
     * 获取所有数据
     *
     * @param outField 输出字段(用,分割)空和*表示所有列
     * @return List<KanbanItem>
     */
    @ApiOperation(value = "获取所有数据", notes = "获取所有数据", httpMethod = "GET")
    @GetMapping("allList")
    public QueryResultModel<?> getAllList(){
        // 获取数据
        List<${entity}> list = ${entity?uncap_first}Service.getAllList();

        return QueryResultModel.ok(list);
    }

    /**
     * 根据 主键 获取单条数据
     *
     * @param uuid Uuid
     * @param outField 输出字段(用,分割)空和*表示所有列
     * @return KanbanItem
     */
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", dataType = "string", name = "uuid", value = "Uuid")})
    @ApiOperation(value = "根据 主键 获取单条数据", notes = "根据 主键 获取单条数据", httpMethod = "GET")
    @GetMapping("itemByUuid")
    public QueryResultModel<?> getItemByUuid(@RequestParam String uuid) {
        // 获取数据
        ${entity} item = ${entity?uncap_first}Service.getItemByUuid(uuid);

        return QueryResultModel.ok(item);
    }

    /**
     * 插入对象
     *
     * @param item 插入对象
     * @return KanbanItem
     */
    @ApiImplicitParams({
        @ApiImplicitParam(paramType = "body", dataTypeClass = ${entity}.class, name = "item", value = "插入对象")})
    @ApiOperation(value = "插入对象", notes = "插入对象", httpMethod = "POST")
    @PostMapping()
    public QueryResultModel<?> insert(@RequestBody ${entity} item) {
        // 执行方法
        ${entity} returnValue = ${entity?uncap_first}Service.insert(item);

        // 返回数据
        return QueryResultModel.ok(returnValue);
    }

    /**
     * 删除对象
     *
     * @param item 删除对象
     * @return bool
     */
    @ApiImplicitParams({
        @ApiImplicitParam(paramType = "body", dataTypeClass = ${entity}.class, name = "item", value = "删除对象")})
    @ApiOperation(value = "删除对象", notes = "删除对象", httpMethod = "DELETE")
    @DeleteMapping()
    public QueryResultModel<?> delete(@RequestBody ${entity} item) {
        // 执行方法
        Boolean returnValue = ${entity?uncap_first}Service.delete(item);

        // 返回数据
        return QueryResultModel.ok(returnValue);
    }

    /**
     * 更新对象
     *
     * @param item 更新对象
     * @return ${entity}
     */
    @ApiImplicitParams({
        @ApiImplicitParam(paramType = "body", dataTypeClass = ${entity}.class, name = "item", value = "更新对象")})
    @ApiOperation(value = "更新对象", notes = "更新对象", httpMethod = "PUT")
    @PutMapping()
    public QueryResultModel<?> update(@RequestBody ${entity} item) {
        // 执行方法
        ${entity} returnValue = ${entity?uncap_first}Service.update(item);

        // 返回数据
        return QueryResultModel.ok(returnValue);
    }

}
